import { modal } from 'vue-strap'
import { showMsg, codeExcel } from '../../../../vuex/action'

export default {
  name: 'code-excel',
  data() {
    return {
      title: '导入兑换码文件',
      excelParam: {
        prizeId: +this.prizeId,
        excel: ''
      }
    }
  },
  props: ['showCodeExcel', 'prizeId'],
  components: {
    'vue-modal': modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xCodeExcel: codeExcel
    }
  },
  methods: {
    showImportExcel() {
      this.showCodeExcel = true
      this.excelParam.excel = ''
    },
    submit() {
      let formData = new FormData()
      formData.append('prizeId', +this.prizeId)
      formData.append('excel', this.$els.file.files[0])

      this.xCodeExcel(formData)
        .then(() => {
          this.showCodeExcel = false
          this.excelParam.excel = ''
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
